import request from '@/utils/request.js'
// 注册接口
export const registerAPI = ({ username, password, repassword }) => {
  return request({
    url: '/api/reg',
    method: 'POST',
    data: {
      username, password, repassword
    }
  })
}
// 登录接口
export const loginAPI = ({ username, password }) => {
  return request({
    url: '/api/login',
    method: 'POSt',
    data: {
      username,
      password
    }
  })
}
// 获取用户基本信息
export const getUserInfoAPI = () => {
  return request({
    url: '/my/userinfo'
  })
}
// 获取侧边栏数据
export const getAsideData = () => {
  return request({
    url: '/my/menus'
  })
}
// 更新用户基本资料
export const updateUserInfoAPI = ({ id, nickname, email }) => {
  return request({
    url: '/my/userinfo',
    method: 'PUT',
    data: {
      id,
      nickname,
      email
    }
  })
}
// 更新用户头像
export const updateUserAvatarAPI = (avatar) => {
  return request({
    url: '/my/update/avatar',
    method: 'PATCH',
    data: {
      avatar
    }
  })
}
// 更改用户密码
export const updateUserPasswordAPI = ({ old_pwd, new_pwd, re_pwd }) => {
  return request({
    url: '/my/updatepwd',
    method: 'PATCH',
    data: {
      old_pwd, new_pwd, re_pwd
    }
  })
}
// 获取文章分类
export const getArticleClassificationAPI = () => {
  return request({
    url: '/my/cate/list'
  })
}
// 添加文章分类
export const addArticleClassification = ({ cate_name, cate_alias }) => {
  return request({
    url: '/my/cate/add',
    method: 'POST',
    data: {
      cate_name, cate_alias
    }
  })
}
// 获取文章分类详情
export const getArticleClassificationParticularsAPI = (id) => {
  return request({
    url: '/my/cate/info',
    params: { id }
  })
}

// 更新文章分类
export const updateArticleClassificationAPI = ({ id, cate_name, cate_alias }) => {
  return request({
    url: '/my/cate/info',
    method: 'PUT',
    data: {
      id, cate_name, cate_alias
    }
  })
}
// 删除文章分类
export const deleteArticleClassificationAPI = (id) => {
  return request({
    url: '/my/cate/del',
    method: 'DELETE',
    params: {
      id
    }
  })
}
// 获取文章列表
export const getArticleListAPI = ({ pagenum, pagesize, cate_id, state }) => {
  return request({
    url: '/my/article/list',
    params: {
      pagenum, pagesize, cate_id, state
    }
  })
}
export const uploadArticleAPI = (fd) => {
  return request({
    url: '/my/article/add',
    method: 'POST',
    data: fd // 参数要的是表单对象, 不能写普通对象, axios内部会判断, 如果是表单对象, 传递的请求体会设置Content-Type: form-data与后端对应
  })
}
export const getArticleDetailFn = (id) => {
  return request({
    url: '/my/article/info',
    params: {
      id
    }
  })
}
export const delArticleAPI = (id) => {
  return request({
    url: '/my/article/info',
    method: 'DELETE',
    params: {
      id
    }
  })
}
